package com.csu.service.serviceImpl;

import com.csu.common.CommonResponse;
import com.csu.entity.Attendance;
import com.csu.entity.User;
import com.csu.mapper.ClassesMapper;
import com.csu.mapper.UserMapper;
import com.csu.service.ClassesService;
import com.csu.vo.ClassStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ClassesServiceImpl implements ClassesService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    ClassesMapper classesMapper;

    /**
     *获取班级成员
     */
    @Override
    public CommonResponse<List<User>> getClassUsers(int classId) {
        List<User> userList = userMapper.getUserListByClassId(classId);
        if(!userList.isEmpty())
            return CommonResponse.createForSuccess("获取班级成员成功", userList);
        return CommonResponse.createForError("获取班级成员失败");
    }

    /**
     * 删除班级
     */
    @Override
    public CommonResponse<Object> deleteClass(int classId) {
        Integer rows = classesMapper.deleteClass(classId);
        if(rows != 0)
            return CommonResponse.createForSuccess("删除班级成功", null);
        return CommonResponse.createForError("删除班级失败");
    }

    /**
     * 注册班级
     */
    @Override
    public CommonResponse<Object> postClass(String name){
        int id = classesMapper.getMaxId() + 1;
        Integer rows = classesMapper.insertClass(id, name);
        if(rows != 0)
            return CommonResponse.createForSuccess("注册班级成功", id);
        return CommonResponse.createForError("注册班级失败");
    }

    /**
     * 修改班级状态
     */
    @Override
    public CommonResponse<Object> changeStatus(int classId, int status){
        Integer rows = classesMapper.changeStatus(classId, status);
        if(rows != 0)
            return CommonResponse.createForSuccess("修改班级状态成功", null);
        return CommonResponse.createForError("修改班级状态失败");
    }
}
